#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


static bool my_cmp(pair<int, int>p1, pair<int, int>p2)
{
    if (p1.first < p2.first)
    {
        return true;
    }
    return false;
}

vector<int> advantageCount(vector<int>& nums1, vector<int>& nums2) {
    vector<int>nums(nums1.size(), 0);

    vector<pair<int, int>>pa(nums2.size(), { 0,0 });

    for (int i = 0; i < nums2.size(); i++)
    {
        pa[i].first = nums2[i];
        pa[i].second = i;
    }

    sort(nums1.begin(), nums1.end());
    sort(pa.begin(), pa.end(), my_cmp);

    int left = 0;
    int right = nums2.size();

    int cur = 0;

    while (cur < right)
    {
        if (nums1[cur] > pa[left].first)
        {
            nums[pa[left].second] = nums1[cur];
            cur++;
            left++;
        }
        else
        {
            nums[pa[right - 1].second] = nums1[cur];
            right--;
            cur++;
        }

    }
    return nums;


}
int main()
{
    vector<int>nums1 = { 12,24,8,32 };
    vector<int>nums2 = { 13,25,32,11 };
    advantageCount(nums1, nums2);
	return 0;
}